<%
/**
 * singleSelect 外部调用的职工单选弹处对话框
 * 
 * @author  李荣华
 * @version v1.0
 * @date    2017-12-29
 * @since   JSP 2.3.1
 */
%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="at" uri="http://www.jketing.com/at"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>职工单选</title>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
<meta content="no-cache" http-equiv="Pragma"/>
<meta content="no-cache" http-equiv="Cache-Control"/>
<meta content="0" http-equiv="Expires"/>
<meta name="GENERATOR" content="MSHTML 8.00.6001.18854"/>
<link rel="stylesheet" id="dialog" type="text/css" href="<at:url css="dialog.css"/>" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/scripts/common/zTree/zTreeStyle/zTreeStyle.css" />
<script type="text/javascript" src="${pageContext.request.contextPath}/scripts/jquery.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/scripts/common.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/scripts/common/zTree/jquery.ztree.all.min.js"></script>
<script type="text/javascript" src="<at:url js="dialog.js"/>"></script>
<script type="text/JavaScript">
    var MyObject = window.dialogArguments;
	
	//取人员数据
	function getManList(orgId){
		//alert(orgId);
		var url = "${pageContext.request.contextPath}/employee/getEmployeeList?organId="+orgId+"&t="+ new Date().getTime();
	   $.getJSON(url,function(data){
		    var list = document.getElementById("peopleList");
		    list.options.length = 0;
			//遍历JSON中的每个entry 			
			$.each(data,function(entryIndex,entry){
			    list.options.length=list.options.length+1;
			    list.options[list.options.length-1].text = entry['name'];
			    list.options[list.options.length-1].value = entry['id'];	
			    //list.options[list.options.length-1].title=entry['name'] + "  "+ entry['sex'] + "\n"+ entry['organ'] + "  "+ entry['qualification'] + "\n" + entry['professionalSkill'];
			}); 
		}); 
	}

	function isSelected() 
    {
    	var list=document.getElementById("peopleList");
    	var selected = false;        
        for (var i = 0; i < list.options.length; i++) {        
            if (list.options[i].selected == true) {     
                selected = true;        
                break;        
            }        
        }              
		return selected;
    }
    
    function okClick() 
    {
    	var list=document.getElementById("peopleList");
        if ( isSelected() ) 
	    {
        	MyObject.id.value = list.options[list.options.selectedIndex].value;
		    MyObject.name.value = list.options[list.options.selectedIndex].text;
		    close();    
	    }
	    else
	    {  
	        alert('你没有选择!');
	    }
    }
    
    function doCancel()
    {
        window.close();
    }
    
    var zTree;
	var zNodes = eval('(' + '${topTree}' + ')');

	var setting = {
			data: {
				simpleData: {
					enable: true,
					idKey: "id",
					pIdKey: "pId"
				}
			},
			async: {
				enable: true,
				type:"get",
				url: "${pageContext.request.contextPath}/organ/getSubTree",
				autoParam: ["id"]
			},
			callback: {
				onClick: zTreeOnClick
			}
		};
	
	function refreshTree() {
		//zTree = $("#tree").zTree(setting, zNodes);
		$.fn.zTree.init($("#tree"), setting, zNodes);
		zTree = $.fn.zTree.getZTreeObj("tree");
	}
	
	function zTreeOnClick(event, treeId, treeNode) {
		getManList(treeNode.id);
	}
	
	function zTreeOnAsyncError(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) {
		alert("zTreeOnAsyncError");
	}
	
	$(document).ready(function(){
		refreshTree();	
	});
	
	//取机构数据
	function getTree(obj){
		var id=obj.options[obj.options.selectedIndex].value;
		$.getJSON("${pageContext.request.contextPath}/organ/getTree?id="+id,function(data){
			zNodes = data;
			refreshTree();
		}); 
	}
</script>
<base target="_self"/>
</head>
<body>
<form action="">
	<div class="dialog_radio2">
		<div class="ele_tree">
	    	<div class="ele_tree_select">
	        	<select name="root" onchange="getTree(this);">
					<c:forEach items="${list}" var="item">
						<option value="${item.id}">${item.name}</option>
					</c:forEach>
				</select>
	        </div>
	        <div class="ele_tree_con"><ul id="tree" class="ztree"></ul></div>
	    </div>
		<div class="arrow"></div>
		<div class="select_lump">
			<select multiple="multiple" id="peopleList" size="5" style="width: 130px; height: 400px;margin:0px;padding:0px;">
			</select>
		</div>
		<div class="clear_div"></div>
		<div class="dialog_button dialog_button2">
			<div class="button_left button_left2" onclick="okClick();">
				确定
			</div>
			<div class="button_right button_right2" onclick="doCancel();">
				取消
			</div>
		</div>
	</div>
</form>
</body>
</html>
